package com.sky.module.system.heart.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sky.module.system.heart.dao.HeartMapper;
import com.sky.module.system.heart.domain.entity.HeartEntity;
import com.sky.module.system.heart.domain.form.HeartFormQuery;
import com.sky.module.system.heart.service.HeartService;
import com.sky.module.system.loginlog.controller.LoginLogController;
import com.sky.module.system.test.controller.TestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author
 * @date 2023/3/11 15:00
 **/
@Service
public class HeartServiceImpl implements HeartService {

    @Autowired
    private HeartMapper heartMapper;

    /***
     * @description TODO
     * @param heartFormQuery
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.sky.module.system.heart.domain.entity.HeartEntity>
     * @date 2023/3/11 15:10
     *
     */
    @Override
    public Page<HeartEntity> queryPage(HeartFormQuery heartFormQuery) {
        final Page<HeartEntity> entityPage = new Page<>();
        final LambdaQueryWrapper<HeartEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(heartFormQuery.getKey()), HeartEntity::getProcessNo, heartFormQuery.getKey()).or()
                .like(StringUtils.isNotBlank(heartFormQuery.getKey()), HeartEntity::getProjectPath, heartFormQuery.getKey())
                .like(StringUtils.isNotBlank(heartFormQuery.getKey()), HeartEntity::getServerIp, heartFormQuery.getKey());
        wrapper.ge(StringUtils.isNotBlank(heartFormQuery.getBeginTime()), HeartEntity::getProcessStartTime, heartFormQuery.getBeginTime());
        wrapper.le(StringUtils.isNotBlank(heartFormQuery.getEndTime()), HeartEntity::getProcessStartTime, heartFormQuery.getEndTime());
        wrapper.orderByDesc(HeartEntity::getProcessStartTime);
        Page<HeartEntity> heartEntityPage = heartMapper.selectPage(entityPage, wrapper);
        return heartEntityPage;
    }

}
